package main

import (
	"google.golang.org/grpc"
	"grpc-6/pb/services"
	"log"
	"net"
)

func main() {
	//RunDownloadService("tcp", "8080")

	//无ssl验证, tcp-ip服务
	rpcServer := grpc.NewServer()
	services.RegisterDownloadServiceServer(rpcServer, &services.DownloadServer{})
	listen, err := net.Listen("tcp", ":8081")
	if err != nil {
		log.Fatalf("启动网络监听失败 %v\n", err)
	}
	rpcServer.Serve(listen)
}

func RunDownloadService(network, port string) error {
	server := grpc.NewServer()
	services.RegisterDownloadServiceServer(server, &services.DownloadServer{})

	lis, err := net.Listen(network, port)
	if err != nil {
		log.Fatalf("net.Listen err: %v", err)
		return err
	}

	err = server.Serve(lis)
	if err != nil {
		log.Fatalf("net.Listen err: %v", err)
	}
	return err
}
